package Code.Objects.Characters.Player.Weapons.Ranged.AmmoBased.RapidFire.MachineGun;

import org.jrabbit.base.managers.ResourceManager;
import org.jrabbit.base.managers.window.WindowManager;
import org.jrabbit.standard.game.graphics.skins.image.ImageSkin;
import org.jrabbit.standard.game.objects.text.TextSprite;

import Code.Objects.Characters.Player.Player;
import Code.Objects.Characters.Player.Skins.Weapons.PlayerMachineGunSkin;
import Code.Objects.Characters.Player.Weapons.WeaponSoundPlayer;
import Code.Objects.Characters.Player.Weapons.Ranged.AmmoBased.RapidFire.PlayerRapidFireWeapon;
import Code.Objects.Effects.Projectiles.Player.Medium.MachineGunBullet;
import Code.Objects.Effects.Visual.GunfireBursts.Large.LargeGunfireBurst1;

public class PlayerMachineGun extends PlayerRapidFireWeapon
{
	private TextSprite readout;
	
	public PlayerMachineGun(Player p)
	{
		super(new PlayerMachineGunSkin(), p);
		cameraModePreference = 2;
		ammoPerClip = 45;
		maxClips = 9;
		shotInterval = 1000;
		offset = 40;
		reloadDuration = 17000;
		fillAmmo();
		readout =  new TextSprite("Ammo In Clip: " + ammoInClip + "\nSpare Ammo: " + spareAmmo);
		readout.useScreenCoords(true);
		readout.location().set(WindowManager.getDisplayWidth() - 200, 14);
		
		icon = new ImageSkin("Resources/Images/GUI/Game/Weapon Selection/Icons/Machine Gun.png");
	}
	
	public void outOfAmmo()
	{
		WeaponSoundPlayer.playMachineGunSound(1f, 2);
	}
	
	public void beginReload()
	{
		super.beginReload();
		WeaponSoundPlayer.playMachineGunSound(1f, 1);
	}
	
	public void fire()
	{
		owner.getWorld().addEffect(new MachineGunBullet(location, rotation.angle(), 50), "Effects B");
		LargeGunfireBurst1 gunBurst = new LargeGunfireBurst1(this, 38, owner.getWorld());
		gunBurst.scalar().set(0.6f);
		gunBurst.color().set(1f, 0.8f + ResourceManager.random().nextFloat() * 0.2f, 0.3f);
		getOwner().getWorld().addRenderable(gunBurst, "Effects B");
		getOwner().getWorld().addUpdateable(gunBurst);
		WeaponSoundPlayer.playMachineGunSound(0.6f, 0);
	}
	
	public void renderGUI()
	{
		super.renderGUI();
		readout.setText("Ammo In Clip: " + ammoInClip + "\nSpare Ammo: " + spareAmmo);
		readout.render();
	}
}
